<template>
  <div class="news-page" v-bind="$attrs">
    <div class="header">
      <div>
        <h3>共发布 {{ total }} 期</h3>
      </div>
      <div class="filters">
        <el-date-picker v-model="value" type="daterange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期" @change="handleChange" />
        <el-input v-model="input" @change="handleInputChange" placeholder="搜索新闻..." />
      </div>
    </div>
    
    <div class="news-list">
      <div v-for="item in content" :key="item.id" class="news-item">
        <img class="news-image" :src="item.coverImage" :alt="item.title">
        <div class="news-info">
          <h4>{{ item.title }}</h4>
          <p>{{ item.description }}</p>
          <div class="news-footer">发布时间：{{ item.publishTime }}</div>
        </div>
      </div>
    </div>
    
    <div v-if="!content || content.length === 0" class="empty-state">
      暂无发布的新闻
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
import { newsIssueList } from '@/api/newsApi'

const total = ref(0)
const content = ref([])

newsIssueList({ current: 1, currentSize: 10 }).then(res => {
  total.value = res.data.total
  content.value = res.data.records
})

const value = ref()
const input = ref('')

const handleChange = (val) => {
  value.value = val
}

const handleInputChange = (val) => {
  input.value = val
}

</script>

<style scoped>
.news-page {
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.filters {
  display: flex;
  gap: 10px;
}

.news-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.news-item {
  display: flex;
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}

.news-image {
  width: 200px;
  height: 120px;
  object-fit: cover;
  margin-right: 15px;
}

.news-info {
  flex: 1;
}

.news-info h4 {
  margin: 0 0 10px;
  font-size: 18px;
}

.news-info p {
  margin: 0 0 10px;
  color: #666;
}

.news-footer {
  font-size: 14px;
  color: #999;
}

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: #999;
}
</style>
